package com.zhuchaooasystem.adapter.holder;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zhuchaooasystem.R;
import com.zhuchaooasystem.entity.DailyEntity;
import com.zhuchaooasystem.ui.common.ImagePagerActivity;
import com.zhuchaooasystem.utils.AppUtils;
import com.zhuchaooasystem.utils.ScreenUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yinsi
 */
public class DailyImageListHolder extends BaseViewHolder<DailyEntity.ResultBean.SuccessfulBean.ArryImgBean> {
    //----
    private int num_column;
    private RelativeLayout relative_rootview;
    private ImageView iv_cover;
    //----
    private Context mContext;
    private int image_height;
    private List<DailyEntity.ResultBean.SuccessfulBean.ArryImgBean> imageList;

    public DailyImageListHolder(ViewGroup parent, List<DailyEntity.ResultBean.SuccessfulBean.ArryImgBean> imageList,int num_column) {
        super(parent, R.layout.item_activity_daily_image);
        this.imageList = imageList;
        mContext = getContext();
        this.num_column=num_column;
        //----
        relative_rootview = $(R.id.item_act_daily_image_relative_rootview);
        iv_cover = $(R.id.item_act_daily_image_iv_cover);
        //----
        image_height = (ScreenUtils.getScreenWidth((Activity) mContext) - ScreenUtils.dip2px(mContext, 30)) / num_column-ScreenUtils.dip2px(mContext, 4);
        iv_cover.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, image_height));

    }

    @Override
    public void setData(final DailyEntity.ResultBean.SuccessfulBean.ArryImgBean image) {
        //----
        Glide.with(mContext).load(image.getFilePath()).asBitmap().placeholder(R.drawable.ic_image_default).error(R.drawable.ic_image_default).centerCrop().into(iv_cover);
        //----
        relative_rootview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<String> list_images_temp = new ArrayList<>();
                for (int i = 0; i < imageList.size(); i++) {
                    list_images_temp.add(imageList.get(i).getFilePath());
                }
                Bundle bundle = new Bundle();
                bundle.putStringArrayList("images", list_images_temp);
                bundle.putBoolean("isCache", true);
                bundle.putInt("position", getDataPosition());
                AppUtils.jump(mContext, ImagePagerActivity.class, bundle);
            }
        });
    }

}
